<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>livevalidation example</title>
<link rel="stylesheet" type="text/css" href="css/live_validation.css">
<script type="text/javascript" src="js/livevalidation_standalone.js"></script>
</head>
<body>
	<form method="post" action="#" id="example_form">
		<fieldset>
		  <legend>Example of form validation</legend>
		  	<p>Enter a password: 
			      <input type="password" id="password">
				  <br>
				  Confirm password:
				  <input type="password" id="confirmPassword">
			</p>
			<p><label class="displayBlock" for="email">Email (10 - 20 characters long):</label><input type="text" id="email"></p>
			<p><label class="displayBlock" for="acceptance">Acceptance (required):</label><input type="checkbox" class="checkbox" id="acceptance"></p>
			<p><label class="displayBlock" for="presence">Presence (required):</label><textarea cols="10" rows="2" class="shallow" id="presence"></textarea></p>
	    <p><input type="submit" value="Test me!" class="submit"></p>
	  </fieldset>
	</form>
	
	<script type="text/javascript">
	    //we must put this script behind the form element.
		var passwordField = new LiveValidation('password');
		passwordField.add( Validate.Presence,{ failureMessage: '请输入密码！'} );
		passwordField.add( Validate.Numericality,{ failureMessage: '密码只能为数字！'} );
		
		var confirmPasswordField = new LiveValidation('confirmPassword');
		confirmPasswordField.add( Validate.Confirmation, { match: 'password'} );
	
		var emailField = new LiveValidation('email');
		emailField.add( Validate.Email );
		
		var acceptanceField = new LiveValidation('acceptance');
		acceptanceField.add( Validate.Acceptance );
		
		var presenceField = new LiveValidation('presence');
		presenceField.add( Validate.Presence );

        var automaticOnSubmit = document.getElementById('example_form').onsubmit;
        document.getElementById('example_form').onsubmit = function(){
         var valid = automaticOnSubmit();
         if(!valid)
          return false;
        }
	</script>
</body>
</html>